<?php
$group_project = $vars ['group_project'];
$semester = $vars ['semester'];
$academic_year = $vars ['academic_year'];
$group_guid = $vars ['group_guid'];

$metadata_options = array (
		array (
				'name' => 'group_project',
				'value' => $group_project 
		),
		array (
				'name' => 'semester',
				'value' => $semester 
		),
		array (
				'name' => 'academic_year',
				'value' => $academic_year 
		) 
);
$options = array (
		'type' => "object",
		'subtype' => 'project',
		'container_guid' => $group_guid,
		'hidden_register' => $hidden_register,
		'metadata_name_value_pairs' => $metadata_options 
);

$projectlist = elgg_get_entities_from_metadata ( $options );
foreach ( $projectlist as $project ) {
	$project->state = STATE_CLOSE;
}

// set state of class is close
$projectlists = elgg_get_entities ( array (
		'type' => "object",
		'subtype' => "projectlist",
		'container_guid' => $vars ['group_guid'] 
) );

foreach ( $projectlists as $projectlist ) {
	$ar_groupproject = explode ( ",", $projectlist->group_project );
	$ar_semester = explode ( ",", $projectlist->semester );
	$ar_academic = explode ( ",", $projectlist->academic_year );
	$classes_state = explode ( ",", $projectlist->classes_state );
	
	for($t = 0; $t < count ( $ar_groupproject ); $t ++) {
		$old_semester = $ar_semester [$t];
		$old_academic_year = $ar_academic [$t];
		if ($ar_groupproject [$t] == $group_project && $old_semester == $semester && $old_academic_year == $academic_year) {
			
			$str = '';
			for($i = 0; $i < count ( $classes_state ); $i ++) {
				if ($i == $t) {
					if ($i == 0) {
						$str .= "" . STATE_CLOSE;
					} else {
						$str .= "," . STATE_CLOSE;
					}
				} else {
					if ($i == 0) {
						$str .= $classes_state [$i];
					} else {
						$str .= "," . $classes_state [$i];
					}
				}
			}
			
			$projectlist->classes_state = $str;
		}
	}
}
forward ( REFERER );
